import Vue from 'vue'
import App from './App.vue'
import router from './router'
import './assets/css/global.css'
import TreeTable from 'vue-table-with-tree-grid'
//導入富文本編輯器
import VueQuillEditor from 'vue-quill-editor'

//導入nprogress
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'


import axios from 'axios'

//配置請求的跟路徑
axios.defaults.baseURL = 'https://lianghj.top:8888/api/private/v1/'
//在request攔截器中,展示進度條NProgress

//請求攔截器
axios.interceptors.request.use(config=>{
  NProgress.start()
  config.headers.Authorization = window.sessionStorage.getItem('token')
  //在最後必須return config
  return config
})
//在request攔截器中,隱藏進度條NProgress
axios.interceptors.response.use(config=>{
  NProgress.done()
  return config
})

Vue.prototype.$http = axios
Vue.config.productionTip = false
Vue.component('tree-table',TreeTable)

//將富文本編輯器註冊為全局可用的組件
Vue.use(VueQuillEditor)

//過濾器
Vue.filter('dataFormat',function(originVal){
  const dt = new Date(originVal*1000)
  const y = dt.getFullYear()
  const m = (dt.getMonth()+1+'').padStart(2,'0')
  const d = (dt.getDate()+'').padStart(2,'0')
  const hh = (dt.getHours()+'').padStart(2,'0')
  const mm =  (dt.getMinutes()+'').padStart(2,'0')
  const ss = (dt.getSeconds()+'').padStart(2,'0')
  return `${y}-${m}-${d} ${hh}:${mm}:${ss}`
})

new Vue({
  router,
  render: h => h(App)
}).$mount('#app')
